package com.baseframe.system.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baseframe.system.entity.BaseDict;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baseframe.system.entity.request.BaseDictRequest;
import com.baseframe.system.entity.vo.BaseDictVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**

* @description 针对表【base_dict(字典表)】的数据库操作Mapper
* @createDate 2023-07-01 21:13:12
* @Entity com.baseframe.system.entity.BaseDict
*/
public interface BaseDictMapper extends BaseMapper<BaseDict> {


    @Select("<script>" +
            "select * from base_dict " +
            "<where>" +
            " is_deleted = 0 and parent is null " +
            "<if test=\" request.name!=null &amp;&amp; request.name !='' \">" +
            " and `name` = #{request.name}" +
            "</if>" +
            "</where>" +
            "order by create_time" +
            "</script>")
    public Page<BaseDictVO> getParentVoPage(Page<BaseDictVO> page,@Param("request") BaseDictRequest request);

    @Select("select id, parent, code, name, value, sort, remark, status, is_deleted from base_dict where is_deleted = 0 and parent = #{parent} order by sort")
    public List<BaseDictVO> getChildNodes(@Param("parent")Long parent);

    @Select("select * from base_dict where is_deleted = 0 order by create_time")
    List<BaseDictVO> loadAll();

    @Select("select * from base_dict where is_deleted = 0 and status = 1 and code = #{code} limit 1")
    BaseDictVO loadDictByCode(String code);

    @Select("select * from base_dict where is_deleted = 0 and status = 1 and parent = #{parent}")
    List<BaseDictVO> getChildNodesByEnableStatus(@Param("parent") Long parent);
}




